<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        <input type="text" name="" id="num">
        <button id="btn">是否是两位数</button>
    </div>
    <script>
        window.onload = function(){
            var num = document.getElementById('num')
            var btn = document.getElementById('btn')

            function sum(){
                var s = num.value.length
                console.log(s);
                if(s == 2){
                    alert('√是两位数')
                }else{
                    alert(`这是${s}位数`)
                }

            }
            btn.onclick = function(){
                sum()
            }
            num.onkeydown = function(e){
                if(e.keyCode == 13){
                    sum()
                }
                // console.log(e.keyCode);
            }
        }
    </script>
</body>
</html>